package com.xr.core.system.common.base;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class MyServiceImpl<M extends MyBaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T> implements MyService<T> {

    /**
     * 批量删除数据
     *
     * @param t      实体类
     * @param idList id集合
     * @return 执行结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean batchDelete(List<Long> idList, T t) {
        return SqlHelper.retBool(baseMapper.deleteWithFill(t, new LambdaQueryWrapper<>(t)
                .in(T::getId, idList)));
    }

    /**
     * 删除数据
     *
     * @param t       实体类
     * @param wrapper 筛选条件
     * @return 执行结果
     */
    @Override
    public boolean deleteWithFill(T t, Wrapper<T> wrapper) {
        return SqlHelper.retBool(baseMapper.deleteWithFill(t, wrapper));
    }

}
